package com.yz.lzq.liwushuo.ui.setting;

import android.content.Context;
import android.content.SharedPreferences;

import com.yz.lzq.liwushuo.ui.modules.comminterface.OnGetSharedPerfenceDataListener;

/**
 * Created by Administrator on 2016/12/12.
 * SettingActivity的model层
 * 用于处理SharedPerfence的写入和读取
 */

public class SettingActivityModel implements SettingContract.SettingActivityModelInterface {

    @Override
    public void writeUserSharedPerfence(Context context, int gender, int generation) {
        //步骤2-1：创建一个SharedPreferences.Editor接口对象，lock表示要写入的XML文件名，MODE_WORLD_WRITEABLE写操作
        SharedPreferences.Editor editor = context.getSharedPreferences("lock", Context.MODE_WORLD_WRITEABLE).edit();
        //步骤2-2：将获取过来的值放入文件
        editor.putInt("gender", gender);
        editor.putInt("generation", generation);

        //步骤3：提交
        editor.commit();
    }

    @Override
    public void readUserSharedPerfence(Context context, OnGetSharedPerfenceDataListener listener) {
//        获取SharedPreferences对象
        SharedPreferences sp = context.getSharedPreferences("lock", Context.MODE_WORLD_WRITEABLE);
        listener.onGetGenderAndGenration(sp.getInt("gender",99), sp.getInt("generation", 99));
    }


}
